﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 会员卡管理系统
{
    public partial class HouseNow : UserControl
    {
        
        public HouseNow()
        {
            InitializeComponent();
        }
        Vipclass.tb_viphouseinfo tbHouse = new Vipclass.tb_viphouseinfo();
        Vipclass.tbVipHouseMenthod Housementhod = new Vipclass.tbVipHouseMenthod();
        private void btnint_MouseEnter(object sender, EventArgs e)
        {
            btnint.BackgroundImage = Properties.Resources.入住大;
        }

        private void btnint_MouseLeave(object sender, EventArgs e)
        {
            btnint.BackgroundImage = Properties.Resources.入住小;
        }

        private void btnout_MouseEnter(object sender, EventArgs e)
        {
            btnout.BackgroundImage = Properties.Resources.退房大;
        }

        private void btnout_MouseLeave(object sender, EventArgs e)
        {
            btnout.BackgroundImage = Properties.Resources.退房小;
        }

        private void tbxReserch_TextChanged(object sender, EventArgs e)
        {
            Housementhod.tbHousefoFind(lvHouseNow, imageList1, tbxReserch.Text);
        }

        private void HouseNow_Load(object sender, EventArgs e)
        {
            tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
            labHousenum.Text = tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text = tbHouse.Intnouse.ToString();
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
            labHousenum.Text = tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text = tbHouse.Intnouse.ToString();
        }

        private void lvHouseNow_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if(lvHouseNow.SelectedItems.Count>0)
                {
                    string strshow = lvHouseNow.SelectedItems[0].Text;
                    labHouseid.Text = strshow;
                    tbHouse = Housementhod.tbHousetoshow(strshow);
                    labHousestay.Text = (int)tbHouse.Bolhousestay>0? "已住":"未住";
                    if(labHousestay.Text=="已住")
                    {
                        lvHouseNow.SelectedItems[0].ImageIndex = 1;
                    }
                    else
                    {
                        lvHouseNow.SelectedItems[0].ImageIndex = 0;
                    }
                    labVipid.Text = tbHouse.Strvipid;
                    labVipname.Text = tbHouse.Strvipname;
                    if (tbHouse.Dtusedate.ToShortDateString()=="0001/1/1")
                    {
                        labUsedate.Text = "----";
                    }
                    else
                    {
                        labUsedate.Text = tbHouse.Dtusedate.ToString();
                    }
                }
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }

        private void btnout_Click(object sender, EventArgs e)
        {
            if (lvHouseNow.SelectedItems.Count > 0)
            {
                if (labHousestay.Text == "未住")
                {
                    MessageBox.Show("房间为空！", "请重新选择");
                }
                else
                {
                    outfrm outfrm = new outfrm();
                    outfrm.Text = labHouseid.Text + "退房";
                    if(outfrm.ShowDialog()==DialogResult.Yes)
                    {
                        tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
                        labHousenum.Text = tbHouse.Inthousenum.ToString();
                        labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                        labNouse.Text = tbHouse.Intnouse.ToString();
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择要退房的房间！", "房间未选中");
            }
        }

        private void btnint_Click(object sender, EventArgs e)
        {
            if (lvHouseNow.SelectedItems.Count > 0)
            {
                if (labHousestay.Text == "已住")
                {
                    MessageBox.Show("此房有人入住，请选择其他房间！", "提示");
                }
                else
                {
                    Stayfrm stay = new Stayfrm();
                    stay.Text = labHouseid.Text + "入住";
                    if(stay.ShowDialog()==DialogResult.Yes)
                    {
                        tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
                        labHousenum.Text = tbHouse.Inthousenum.ToString();
                        labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                        labNouse.Text = tbHouse.Intnouse.ToString();
                        lvHouseNow_SelectedIndexChanged(null, null);

                    }
                }
            }
            else
            {
                MessageBox.Show("请选择入住的房间！", "房间未选中");
            }
        }

        private void 入住ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lvHouseNow.SelectedItems.Count > 0)
            {
                if (labHousestay.Text == "已住")
                {
                    MessageBox.Show("此房有人入住，请选择其他房间！", "提示");
                }
                else
                {
                    Stayfrm stay = new Stayfrm();
                    stay.Text = labHouseid.Text + "入住";
                    if (stay.ShowDialog() == DialogResult.Yes)
                    {
                        tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
                        labHousenum.Text = tbHouse.Inthousenum.ToString();
                        labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                        labNouse.Text = tbHouse.Intnouse.ToString(); tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
                        labHousenum.Text = tbHouse.Inthousenum.ToString();
                        labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                        labNouse.Text = tbHouse.Intnouse.ToString();
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择入住的房间！", "房间未选中");
            }
        }

        private void 退房ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lvHouseNow.SelectedItems.Count > 0)
            {
                if (labHousestay.Text == "未住")
                {
                    MessageBox.Show("房间为空！", "请重新选择");
                }
                else
                {
                    outfrm outfrm = new outfrm();
                    outfrm.Text = labHouseid.Text + "退房";
                    if (outfrm.ShowDialog() == DialogResult.Yes)
                    {
                        tbHouse = Housementhod.tbHousefoFill(lvHouseNow, imageList1);
                        labHousenum.Text = tbHouse.Inthousenum.ToString();
                        labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                        labNouse.Text = tbHouse.Intnouse.ToString();
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择要退房的房间！", "房间未选中");
            }
        }
    }
}
